﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using GtsServer.Common;
using System.Data;

namespace GtsServer.DAL {
    public partial class InitialSettingDAL {
        public InitialSettingDAL() {
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select I.Id,I.PrizeId,I.InitialSettingcount,p.PrizeTypeID,p.Name ");
            strSql.Append(" FROM InitialSetting I left join Prize p on I.PrizeId=p.ID ");
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(GtsServer.Model.InitialSetting model) {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into InitialSetting(");
            strSql.Append("PrizeId,InitialSettingcount)");
            strSql.Append(" values (");
            strSql.Append("@PrizeId,@InitialSettingcount)");
            SqlParameter[] parameters = {
					new SqlParameter("@PrizeId", SqlDbType.Int,4),
					new SqlParameter("@InitialSettingcount", SqlDbType.Int,4)};
            parameters[0].Value = model.PrizeId;
            parameters[1].Value = model.InitialSettingcount;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if(obj == null) {
                return 0;
            } else {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(GtsServer.Model.InitialSetting model) {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update InitialSetting set ");
            strSql.Append("PrizeId=@PrizeId,");
            strSql.Append("InitialSettingcount=@InitialSettingcount");
            strSql.Append(" where Id=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@PrizeId", SqlDbType.Int,4),
                    new SqlParameter("@InitialSettingcount",SqlDbType.Int,4),
					new SqlParameter("@ID", SqlDbType.Int,4)};
            parameters[0].Value = model.PrizeId;
            parameters[1].Value = model.InitialSettingcount;
            parameters[2].Value = model.Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if(rows > 0) {
                return true;
            } else {
                return false;
            }
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ID) {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from InitialSetting ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
            parameters[0].Value = ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if(rows > 0) {
                return true;
            } else {
                return false;
            }
        }

    }
}
